<?php
namespace app\serversms\logic;

use \app\manage\logic\BaseLogic;

/**
 * @author:      李颖
 * @DateTime:    2017-06-26 16:36:36
 * @Description: 短信记录类
 */
class SmsLog extends BaseLogic
{
	protected $name = 'sms_log';
    protected $config = 'db_config_sms';
    protected $smsLogModel = 'app\serversms\model\SmsLog';

    /*添加一条 "短信发送记录" */
    public function addLog($data)
    {
        return $this->model($this->smsLogModel)->save($data);
    }

    /*添加多条发送记录*/
    public function batchAddLog($data)
    {
        return $this->model($this->smsLogModel)->saveAll($data);
    }

    /*获取短信发送记录列表*/
    public function logList($data): array 
    {
        if($data['status'] !== ''){
            if($data['status'] == 1){
                $_where['status'] = 0;
            }elseif($data['status'] == 0){
                $_where['status'] = ['neq', 0];
            }
        }
        $data['keywords'] !== '' && $_where['mobile'] = ['like', '%' . $data['keywords'] . '%']; 
        !isset($_where) && $_where = true;
    	$res = $this->model($this->smsLogModel)
                    ->where($_where)
                    ->order('id', 'desc')
                    ->paginate(null,false,['page'=>$data['page'],'list_rows'=>$data['listRows']])
                    ->toArray();

        return auto_return_page($res);
    }
}